'''
Created on 18/05/2013

@author: mirta
'''
from werkzeug import generate_password_hash

#from datetime import date

from app import db
from app.models.usuario import Usuario
#from app.models.entidad import Entidad
from app.models.permiso import Permiso
from app.models.rol import Rol
#from app.models.fase import Fase
#from app.models.tipoItem import TipoItem
#from app.models.proyecto import Proyecto
#from app.models.item import Item
#from app.models.atributo import Atributo
#from app.models.linea_base import LineaBase
#from app.models.historial_lb import HistorialLineaBase

print "Cargando datos"

######################################
## Creacion de permisos por defecto###
######################################
per_1 = Permiso('CREAR_USUARIO',None, None)
db.session.add(per_1)
db.session.commit()

per_2 = Permiso('MODIFICAR_USUARIO',None, None)
db.session.add(per_2)
db.session.commit()

per_3 = Permiso('DESACTIVAR_USUARIO',None, None)
db.session.add(per_3)
db.session.commit()

per_4 = Permiso('VER_USUARIO',None, None)
db.session.add(per_4)
db.session.commit()

per_5 = Permiso('CREAR_ROL',None, None)
db.session.add(per_5)
db.session.commit()

per_6 = Permiso('MODIFICAR_ROL',None, None)
db.session.add(per_6)
db.session.commit()

per_7 = Permiso('ELIMINAR_ROL',None, None)
db.session.add(per_7)
db.session.commit()

per_8 = Permiso('VER_ROL',None, None)
db.session.add(per_8)
db.session.commit()

per_9 = Permiso('CREAR_PERMISO',None, None)
db.session.add(per_9)
db.session.commit()

per_10 = Permiso('ELIMINAR_PERMISO',None, None)
db.session.add(per_10)
db.session.commit()

per_15 = Permiso('ACTIVAR_USUARIO',None, None)
db.session.add(per_15)
db.session.commit()

per_16 = Permiso('ADMINISTRACION_USUARIOS',None, None)
db.session.add(per_16)
db.session.commit()

per_17 = Permiso('ADMINISTRACION_ENTIDADES',None, None)
db.session.add(per_17)
db.session.commit()

per_18 = Permiso('ADMINISTRACION_ROLES',None, None)
db.session.add(per_18)
db.session.commit()

per_19 = Permiso('ADMINISTRACION_PROYECTOS',None, None)
db.session.add(per_19)
db.session.commit()

per_20 = Permiso('ADMINISTRACION_FASES',None, None)
db.session.add(per_20)
db.session.commit()

per_21 = Permiso('ADMINISTRACION_PERMISOS',None, None)
db.session.add(per_21)
db.session.commit()

per_22 = Permiso('CREAR_PROYECTO',None, None)
db.session.add(per_22)
db.session.commit()

per_41 = Permiso('ADMINISTRACION_RELACIONES', None, None)
db.session.add(per_41)
db.session.commit()

per_42 = Permiso('ADMINISTRACION_ATRIBUTOS',None, None)
db.session.add(per_42)
db.session.commit()

per_43 = Permiso('CREAR_ATRIBUTO',None, None)
db.session.add(per_43)
db.session.commit()

per_44 = Permiso('ELIMINAR_ATRIBUTO',None, None)
db.session.add(per_44)
db.session.commit()

per_45 = Permiso('ADMINISTRACION_ITEMS',None, None)
db.session.add(per_45)
db.session.commit()

per_46 = Permiso('ADMINISTRACION_TIPOITEMS', None, None)
db.session.add(per_46)
db.session.commit()

per_47 = Permiso('CREAR_TIPOITEM',None, None)
db.session.add(per_47)
db.session.commit()

per_48 = Permiso('MODIFICAR_TIPOITEM',None, None)
db.session.add(per_48)
db.session.commit()

per_49 = Permiso('ELIMINAR_TIPOITEM',None, None)
db.session.add(per_49)
db.session.commit()

per_50 = Permiso('VER_TIPOITEM',None, None)
db.session.add(per_50)
db.session.commit()

per_51 = Permiso('MODIFICAR_PERMISO',None, None)
db.session.add(per_51)
db.session.commit()

per_52 = Permiso('VER_PERMISO',None, None)
db.session.add(per_52)
db.session.commit()

per_53 = Permiso('ADMINISTRACION_LINEAS_BASE',None, None)
db.session.add(per_53)
db.session.commit()

per_69 = Permiso('MODIFICAR_ATRIBUTO',None, None)
db.session.add(per_69)
db.session.commit()

per_70 = Permiso('CONSULTAR_ATRIBUTO',None, None)
db.session.add(per_70)
db.session.commit()

per_71 = Permiso('ADMINISTRACION_SOLICITUDES',None, None)
db.session.add(per_71)
db.session.commit()


Lista3 = [per_1, per_2, per_3, per_4, per_5, per_6, per_7, per_8, per_9, per_10, per_15, per_16, per_17,  per_18, per_19,  per_21, per_22, per_42, per_43, per_44, per_51, per_52]
rol3 = Rol('Administrador de Sistema', 'Rol por defecto del sistema', Lista3)
db.session.add(rol3)
db.session.commit()

Lista4 = [per_19,per_20, per_46, per_47, per_48, per_49, per_50]
rol4 = Rol('Lider Proyecto', 'Rol por defecto del sistema', Lista4)
db.session.add(rol4)
db.session.commit() 

ListaUnica = [rol3]
usu = Usuario('admin', 'admin@admin.com', generate_password_hash('admin'), 'color?', 'azul','ACTIVO', ListaUnica)
db.session.add(usu)
db.session.commit()

print "Datos cargados"